# Set  the minimum  required version  of cmake  for a  project.
cmake_minimum_required(VERSION 2.8)

#操作系统类型
message(STATUS "operating system is ${CMAKE_SYSTEM}")
message(STATUS "current platform is ${CMAKE_SYSTEM_NAME}")

set(CMAKE_BUILD_TYPE "Release" CACHE STRING "build type:Debug Release" FORCE)

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
	add_definitions(-DSYS_POSIX)
	
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
	add_definitions(-DSYS_WINDOWS)
	add_definitions(-D_CRT_SECURE_NO_WARNINGS)  #取消c语言中fopen等函数的警告
	set(CMAKE_CONFIGURATION_TYPES "Release" CACHE STRING "解决方案类型" FORCE)
else()
	add_definitions(-DSYS_POSIX)
endif()

aux_source_directory(. src)

#将头文件放入headers目录下
file(GLOB_RECURSE var_tetgen *.h *.hpp)
source_group("headers" FILES ${var_tetgen})

add_library(tet STATIC ${src} ${var_tetgen}) 
add_executable(tetgen ${src} ${var_tetgen})

#安装头文件
file(GLOB files ./*.h)
set(INC "include")
install(FILES  ${var_tetgen} DESTINATION ${INC})

#安装库文件和可执行程序
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
	install(PROGRAMS build/tetgen DESTINATION bin)
	install(TARGETS tet
			RUNTIME DESTINATION bin
			ARCHIVE DESTINATION lib
			LIBRARY DESTINATION lib
		)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
	install(TARGETS tetgen tet
			RUNTIME DESTINATION bin
			ARCHIVE DESTINATION lib
			LIBRARY DESTINATION lib
		)
endif() 